package com.magic.smartcity.view.me;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.magic.smartcity.beans.FeedbackBean;
import com.magic.smartcity.databinding.FragmentMeFeedbackDetailBinding;
import com.magic.smartcity.interfaces.IUserPresenter;
import com.magic.smartcity.interfaces.base.BaseUserCallBackFragment;

import javax.inject.Inject;

import dagger.hilt.android.AndroidEntryPoint;

@AndroidEntryPoint
public class MeFeedbackDetailFragment extends BaseUserCallBackFragment {

    private FragmentMeFeedbackDetailBinding mBinding;

    @Inject
    IUserPresenter mPresenter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mBinding = FragmentMeFeedbackDetailBinding.inflate(getLayoutInflater());
        mPresenter.registerCallBack(this);
        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("login-user", Context.MODE_PRIVATE);
        String token = sharedPreferences.getString("token", null);
        if (token!=null) {
            int id = getArguments().getInt("id");
            if (id != 0) {
                mPresenter.getFeedbackById(id);
            }
        }
        return mBinding.getRoot();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mPresenter.unRegisterCallBack(this);
    }

    @Override
    public void feedbackByIdLoaded(FeedbackBean bean) {
        super.feedbackByIdLoaded(bean);
        mBinding.title.setText(bean.getTitle());
        mBinding.content.setText(bean.getContent());
        mBinding.createTime.setText("反馈时间: "+bean.getCreateTime());
        mBinding.type.setText("类型: "+bean.getAppType());
    }

    @Override
    public void error(String str) {

    }
}